package com.leo.boot.aop.annotation.handler;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
@Slf4j
public class SafeHandler {

    @Around("@within(com.leo.boot.aop.annotation.Safe) || @annotation(com.leo.boot.aop.annotation.Safe)")
    public Object handle(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            return joinPoint.proceed();
        } catch (Exception e) {
            log.error("invoke {} with {} error", joinPoint.getSignature(), Arrays.toString(joinPoint.getArgs()), e);
            return null;
        }
    }
}
